Skip to content

fix(budgetManager): prevent cost accumulation past limit in warn mode#10

Open
Srejoye wants to merge 1 commit into
Ruthwik000:mainfrom
Srejoye:fix-budgetmanager-warn-mode
Open

fix(budgetManager): prevent cost accumulation past limit in warn mode#10
Srejoye wants to merge 1 commit into
Ruthwik000:mainfrom
Srejoye:fix-budgetmanager-warn-mode

Conversation

@Srejoye
Copy link
Copy Markdown

@Srejoye Srejoye commented May 16, 2026

Problem

In warn mode, track() issued a console.warn() when the projected total exceeded the limit, but then fell through to this.totalSpent += cost. The cost was committed on every over-limit call, causing totalSpent and percentageUsed to grow without bound — making budget status meaningless.

Root Cause

src/core/budgetManager.tstrack(), lines 66–68. After console.warn(), there was no early exit. The this.totalSpent += cost on line 72 runs unconditionally for both modes after the if-block.

Fix

Add return after console.warn(message). The finally block still runs, so the async lock is correctly released. One line changed.

Behaviour

Scenario Before After
warn mode, over-limit call cost committed, totalSpent grows cost rejected, totalSpent frozen at limit
warn mode, percentageUsed after overrun can exceed 100% stays at limit value
block mode throws, no change throws, no change ✓
warn mode, under-limit calls committed normally committed normally ✓

Testing

  • warn mode: totalSpent does not increase after limit is exceeded
  • warn mode: percentageUsed stays at the limit percentage, not beyond
  • warn mode: under-limit calls still accumulate normally
  • block mode: still throws, completely unaffected
  • async lock (releaseLock) still fires in all cases via finally

Closes #4

In warn mode, track() called console.warn() when the projected total exceeded the limit, but then fell through to this.totalSpent += cost, committing the overrun cost anyway. This caused totalSpent and percentageUsed to grow unboundedly past the limit, making budget status meaningless after the first warning.

Add an early return after console.warn() so the cost is not committed when the limit is exceeded in warn mode. The finally block still runs, so the async tracking lock is properly released. Block mode behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(budgetManager): prevent cost accumulation past limit in warn mode

1 participant